<title>学生课程作业/测试管理</title>

<body>
<?php
//必须保证每位学生都在自己已选择课程的小组中，才能够查询到其已选择的课程的作业/测试
/*---------------------一、PHP文件引用----------------------------------*/
require_once 'response.php';
require_once 'connect_config.php';

/*---------------------二、变量参数定义-------------------------------*/
$username = $_GET['username'];
if(!$username)
{
	$username = $_POST['username'];
}
//$username = "student1";
$msg = "";
$courseassign = array();
$coursequiz = array();

/*---------------------三、数据库连接--------------------------------*/
$conn = mysqli_connect(DB_HOST,DB_USER,DB_PWD,DB_NAME,DB_PORT) or die('数据库连接失败');

$query = "select * from mdl_user where username = '$username'";
$data = mysqli_query($conn, $query);         
$row = mysqli_fetch_array($data);//查询学生ID
if($row)
{
	$id = $row['id'];
}
else
{
	$msg =	mysqli_errno($conn);
}
if($id)
{
	$query1 = "select * from mdl_groups_members where userid = '$id'";
	$data1 = mysqli_query($conn, $query1);       
	$i = 0;  
	while($row1 = mysqli_fetch_array($data1))//查询学生所在的课程组ID
	{
		$groupid = $row1['groupid'];
		$query2 = "select * from mdl_groups where id = '$groupid'";
		$data2 = mysqli_query($conn, $query2);
		$row2 = mysqli_fetch_array($data2);//由课程组ID推出课程
		if($row2)
		{
			$courseid = $row2['courseid'];
			$query3 = "select * from mdl_course where id = '$courseid'";
			$data3 = mysqli_query($conn, $query3);
			$row3 = mysqli_fetch_array($data3);//由课程ID查出课程名称
			$courseassign[$i]['coursename'] = $row3['fullname'];
			
			$query4 = "select * from mdl_assign where course = '$courseid'";
			$data4 = mysqli_query($conn, $query4);
			$row4 = mysqli_fetch_array($data4);//由课程ID查出课程作业
			if($row4)
			{
				$courseassign[$i]['assignname'] = $row4['name'];
				$courseassign[$i]['assignment-intro'] = $row4['intro'];
			}
			else
			{
				$courseassign[$i]['assignname'] = "no assignment";
				$courseassign[$i]['assignment-intro'] = "no intro";
			}		
	
			$query5 = "select * from mdl_quiz where course = '$courseid'";
			$data5 = mysqli_query($conn, $query5);
			$row5 = mysqli_fetch_array($data5);//由课程ID查出课程测验
			if($row5)
			{
				$courseassign[$i]['quiz'] = $row5['name'];	
			}
			else
			{
				$courseassign[$i]['quiz'] = "no quiz";
			}
			
		}
		else
		{
			$msg =	mysqli_errno($conn);
		}
		$i++;
	}
/*
	$status = true;
	$msg = "success";
	echo Response::json($status,$msg,$courses);
*/
	foreach($courseassign as $key=>$value)
	{
		if(is_array($value))
		{
			foreach($value as $key1=>$value1)
			{
				echo $key1.': '.$value1.'<br>';
			}
		}
		else
		{
			echo $key.':'.$value.'<br>';
		}
		echo "<br>";
	}
}
else
{
	$status = false;
	$msg = "failure";
	echo Response::json($status,$msg,$courses);
}
?>
</body>

